package danger.mapper.sys;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

import danger.bean.sys.Dictionary;
import danger.bean.sys.DictionaryExample;

public interface DictionaryMapper {
    int countByExample(DictionaryExample example);

    int deleteByExample(DictionaryExample example);

    int deleteByPrimaryKey(String dictionaryid);

    int insert(Dictionary record);

    int insertSelective(Dictionary record);

    List<Dictionary> selectByExample(DictionaryExample example);

    Dictionary selectByPrimaryKey(String dictionaryid);

    int updateByExampleSelective(@Param("record") Dictionary record, @Param("example") DictionaryExample example);

    int updateByExample(@Param("record") Dictionary record, @Param("example") DictionaryExample example);

    int updateByPrimaryKeySelective(Dictionary record);

    int updateByPrimaryKey(Dictionary record);
    
    /*2017.9.6*/
    /**
	 * 根据字典名称查询字典编码
	 * @param name 字典名称
	 * @return 字典编码
	 * @throws SQLException
	 */
	public String getCodeByName(String name) throws SQLException;

	/**
	 * 根据字典编码查询字典名称
	 * @param dictionaryId 字典Id
	 * @return 字典名称
	 * @throws SQLException
	 */
	public String getNameByCode(String dictionaryId) throws SQLException;
	
	/**
	 * 添加字典信息
	 * @param dictionary
	 * @return
	 * @throws SQLException
	 */
	public int addDictionary(Dictionary dictionary) throws SQLException;

	/**
	 * 根据字典Id删除字典信息
	 * @param dictionaryId
	 * @return
	 * @throws SQLException
	 */
	public int deleteDictionary(String dictionaryId) throws SQLException;

	/**
	 * 修改字典信息
	 * @param dictionary
	 * @return
	 * @throws SQLException
	 */
	public int updateDictionary(Dictionary dictionary) throws SQLException;

	/**
	 * 根据字典编码查询字典信息
	 * @param dictionaryId
	 * @return
	 * @throws SQLException
	 */
	public Dictionary getDictionaryById(String dictionaryId) throws SQLException;
	
	/**
	 * 根据条件查询字典信息(字典编号，字典名称， 起始记录数，每页的记录数)
	 * @param condition(dictionaryId 字典编号,name 字典名称,
	 * 					pageBegin 起始记录数,pageSize 每页的记录数,dictionaryId 上级字典编号)
	 * @return
	 * @throws SQLException
	 */
	public List<Dictionary> getDictionaryByConditon(Map<String,Object> condition) throws SQLException;
	
	/**
	 * 根据条件查询字典的总的记录数(字典编号，字典名称)
	 * @param condition(dictionaryId 字典编号,name 字典名称)
	 * @return
	 * @throws SQLException
	 */
	public int getDicCountByConditon(Map<String,Object> condition) throws SQLException;
	
	/**
	 * 根据上级字典编号查询字典信息
	 * @param upDictionaryId(上级字典编号)、pageBegin(起始记录数)、pageSize(返回的记录数)
	 * @return List<SystemDictionary> (下级字典列表)
	 * @throws SQLException
	 */
	public List<Dictionary> getDictionaryByUpDicId(Map<String,Object> dicCondition) throws SQLException;
	
	/**
	 * 查询全部字典列表
	 * @return List<Dictionary> (全部字典列表)
	 * @throws SQLException
	 */
	public List<Dictionary> getAllDictionary() throws SQLException;
	
	/**
	 * 查询字典树信息
	 * @return List<Map<String,Object>>
	 * 返回的map包括(dictionaryId,name,upDictionaryId)
	 * (字典编号，字典名称，上级字典编号)
	 * @throws SQLException
	 */
	public List<Map<String,Object>> getDictionaryTree() throws SQLException;
	/**
	 * 根据上级字典Id查询下一个要插入的下一级字典的编号 
	 * @param upDictionaryId 上级字典Id
	 * @return
	 * @throws SQLException
	 */
	public String getMaxDictionaryId(String upDictionaryId) throws SQLException;
	/**
	 * 根据上级字典Id查询最新的一个下级字典信息
	 * @param upDictionaryId 上级字典Id
	 * @return 最新的一个下级字典信息
	 * @throws SQLException
	 */
	public Dictionary getNewDictionary(String upDictionaryId)throws SQLException;
	
	/**
	 * 上一级字典禁用后，下一级字典也得禁用
	 * @param upDictionaryId 上级字典Id
	 * @throws SQLException
	 */
	public int updateChildNotUse(String upDictionaryId)throws SQLException;
	
	/**
	 * 得到领域
	 * @throws SQLException
	 */
	public List<String> getDomain(String name)throws SQLException;
	
	public List<Map<String, Object>> getDicNameByUpDicId(String upDictionaryId) throws SQLException;
}